



//
//  XQDeiltailVC.m
//  房源、商铺、写字楼详情页
//
//  Created by MB__Lee on 2018/5/24.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "XQDeiltailVC.h"

#import "XQDetailModel.h"

#import "XQDetailCell.h"
#import "XQDetailCellTwo.h"

@interface XQDeiltailVC ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableview;

@property(nonatomic,strong)NSMutableArray *sourceMut; //存放处理后的数据源
@property(nonatomic,strong)XQDetailModel *detailModel; //模型

@end

static NSString *XQDetailCell_Identi = @"XQDetailCell";
static NSString *XQDetailCellTwo_Identi = @"XQDetailCellTwo";

@implementation XQDeiltailVC
-(UITableView *)tableview{
    if (!_tableview) {
        _tableview  = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
        
        [_tableview registerNib:[UINib nibWithNibName:XQDetailCell_Identi bundle:nil] forCellReuseIdentifier:XQDetailCell_Identi];
        [_tableview registerNib:[UINib nibWithNibName:XQDetailCellTwo_Identi bundle:nil] forCellReuseIdentifier:XQDetailCellTwo_Identi];
    }
    return  _tableview;
}
-(NSMutableArray *)sourceMut{
    if (!_sourceMut) {
        _sourceMut = [NSMutableArray array];
    }
    return  _sourceMut;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
}

#pragma mark ---set 方法获取sn
-(void)setSn:(NSString *)sn{
    _sn = sn;
    [self MB_GetSourceWithXQSn:sn];
}
-(void)setModel:(MBFangDetailModel *)model{
    [self MB_GetSourceWithXQSn:model.xq_sn]; //小区 sn
}
-(void)MB_GetSourceWithXQSn:(NSString *)sn{
    
    NSMutableDictionary *dic  = [NSMutableDictionary dictionary];
    dic[@"sn"] = sn;
    [MBNetTool MBPost:Xq_info paramater:dic success:^(id response) {
        
        NSLog(@"%@",response);
        if ([response[@"data"] integerValue] == 10000) {
            XQDetailModel *detailModel  = [[XQDetailModel alloc] initWithDictionary:response[@"data"] error:nil];
            _detailModel = detailModel;
            NSMutableArray *mut =  [detailModel getTableviewDataSource];
            [self.sourceMut addObjectsFromArray:mut];
            
            [self.view addSubview:self.tableview];
            [self.tableview reloadData];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"正在开发中" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles: nil];
            [alert show];
        }
    } failure:^(NSError *error) {
        
    }];
    
}

#pragma mark ---UITableViewDataSource,UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.sourceMut.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 1 || indexPath.row == 2) {
        XQDetailCellTwo * two  = [tableView dequeueReusableCellWithIdentifier:XQDetailCellTwo_Identi];
        two.model = self.sourceMut[indexPath.row];
        
        return  two;
    }else{
        XQDetailCell *one = [tableView dequeueReusableCellWithIdentifier:XQDetailCell_Identi];
        one.model = self.sourceMut[indexPath.row];
        
        return  one;
    }
    
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat hight = 0;
    if (indexPath.row == self.sourceMut.count - 1) {
        hight =  _detailModel.tenCellHight;
    }else{
        hight = 50;
    }
    return  hight;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
